home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / FallingBlocks / Blocks.jar / Blocks.class (.txt) next >
Encoding:
Java Class File  |  2002-03-20  |  2.2 KB  |  55 lines

  1. import javax.microedition.lcdui.Command;
  2. import javax.microedition.lcdui.CommandListener;
  3. import javax.microedition.lcdui.Display;
  4. import javax.microedition.lcdui.Displayable;
  5. import javax.microedition.midlet.MIDlet;
  6. import javax.microedition.midlet.MIDletStateChangeException;
  7.  
  8. public class Blocks extends MIDlet implements CommandListener {
  9.    private Command startCommand = new Command("Start", 1, 1);
  10.    private Command goCommand = new Command("Go", 1, 1);
  11.    private Command exitCommand = new Command("Exit", 1, 1);
  12.    private Command restartCommand = new Command("Restart", 1, 1);
  13.    private BlocksCanvas bcanvas;
  14.    private BlocksHelp bhelp = new BlocksHelp(this);
  15.  
  16.    public Blocks() {
  17.       this.bhelp.addCommand(this.goCommand);
  18.       this.bhelp.addCommand(this.exitCommand);
  19.       this.bhelp.setCommandListener(this);
  20.       this.bcanvas = new BlocksCanvas(this);
  21.       this.bcanvas.addCommand(this.startCommand);
  22.       this.bcanvas.addCommand(this.exitCommand);
  23.       this.bcanvas.setCommandListener(this);
  24.    }
  25.  
  26.    public void startApp() throws MIDletStateChangeException {
  27.       Display.getDisplay(this).setCurrent(this.bhelp);
  28.    }
  29.  
  30.    public void pauseApp() {
  31.    }
  32.  
  33.    public void destroyApp(boolean uncond) {
  34.    }
  35.  
  36.    public void commandAction(Command c, Displayable d) {
  37.       if (c == this.startCommand) {
  38.          this.bcanvas.removeCommand(this.startCommand);
  39.          this.bcanvas.removeCommand(this.exitCommand);
  40.          this.bcanvas.addCommand(this.restartCommand);
  41.          this.bcanvas.addCommand(this.exitCommand);
  42.          this.bcanvas.start();
  43.       } else if (c == this.goCommand) {
  44.          Display.getDisplay(this).setCurrent(this.bcanvas);
  45.          this.bhelp = null;
  46.       } else if (c == this.restartCommand) {
  47.          this.bcanvas.restartGame();
  48.       } else if (c == this.exitCommand) {
  49.          this.destroyApp(false);
  50.          ((MIDlet)this).notifyDestroyed();
  51.       }
  52.  
  53.    }
  54. }
  55.